<?php

namespace app\admin\service;

use app\admin\model\PoliteConfig;
use app\admin\model\PoliteConfigType;
use think\facade\Cache;
use think\Model;

class PoliteConfigService
{
    protected $configM;
    protected $configTypeM;

    public function __construct(){
        $this->configM=new PoliteConfig();
        $this->configTypeM=new PoliteConfigType();
    }

    public function getConfigByTypeName($typeName,$where=[]){
        $returnData=[];
        if($typeName){
            $isType=$this->configTypeM->where(['type_name'=>$typeName])->find();
            if($isType){
                $where[] = ['config_type','=',$isType['id']];
                $returnData=$this->configM->where($where)->select()->toArray();
            }
        }
        return $returnData;
    }

    public function getConfigById($id){
        $returnData=[];
        if(!empty($id)){
            $returnData=$this->configM->where(['id'=>$id])->find();
        }
        return $returnData;
    }

    public function getConfigByName($name){
        $returnData=[];
        if(!empty($name)){
            $returnData=$this->configM->where(['config_value'=>$name])->find();
        }
        return $returnData;
    }

    /*public function getDepartment(){
        $departmentM=new XwqlDepartment();
        $department=$departmentM->select();
        if(count($department)>0){
            $department=$department->toArray();
        }else{
            $department=[];
        }
        return $department;
    }

    public function getDepartmentById($id){
        $departmentM=new XwqlDepartment();
        return $departmentM->find($id);
    }

    public function getDepartmentByName($name){
        $departmentM=new XwqlDepartment();
        $department=$departmentM->select();
        if(count($department)>0){
            $department=$department->toArray();
        }else{
            $department=[];
        }
        foreach ($department as $k=>$v){
            if($v['name']==$name){
                return $v;
            }else{
                foreach ($v['children'] as $k1=>$v1){
                    if($v1['name']==$name){
                        return $v1;
                    }
                }
            }
        }
        return false;
    }*/
}